package com.lagou.util;

import redis.clients.jedis.Jedis;

import java.util.Set;

/**
 * @author bobcheng
 * @date 2020/6/16
 */
public class RedisUtil {

    private RedisUtil() {}

    private static final Jedis JEDIS;

    static {
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        JEDIS = jedis;
    }

    public static Long getIncrId() {
        return JEDIS.incr("id");
    }

    public static void set(String key, String value) {
        JEDIS.set(key, value);
    }

    public static void set(String key, String value, int expireSeconds) {
        JEDIS.set(key, value);
        JEDIS.expire(key, expireSeconds);
    }

    public static String get(String key) {
        return JEDIS.get(key);
    }

    public static Set<String> keys(String pattern) {
        return JEDIS.keys(pattern);
    }
}
